package com.heima.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.heima.domain.dto.TextDTO;
import com.heima.domain.pojo.Text;
import com.heima.domain.query.TextQueryParam;
import com.heima.domain.vo.PageVo;
import com.heima.mapper.TextMapper;
import com.heima.service.TextService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Random;

@Service
public class TextServiceImpl extends ServiceImpl<TextMapper, Text> implements TextService  {
    @Override
    public PageVo pageList(TextQueryParam textQueryParam) {
        PageHelper.startPage(textQueryParam.getPage(),textQueryParam.getPageSize());
        List<Text> textList = baseMapper.pageList(textQueryParam);
        Page<Text> page = (Page<Text>) textList;
        return new PageVo<>(page.getTotal(),page.getResult());
    }

    @Override
    public Text add(TextDTO dto) {
        Text text = new Text();
        text.setTaskNumb("QC" + + System.currentTimeMillis() + "" + new Random().nextInt(9999));
        text.setType(dto.getType());
        text.setWorkNub(dto.getWorkNub());
        text.setCheckSchemaId(dto.getCheckSchemaId());
        text.setStatus(1);
        text.setReason(null);
        text.setExecutor(null);
        text.setExecuteTime(null);
        text.setRoleId(dto.getRoleId());
        text.setCreateBy("admin");

        baseMapper.insert(text);
    return text;
    }


}
